package com.entity;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.util.BB;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 作者 ：lichao
 * 部门 : 开发二部
 * 时间 ：2018/9/26
 * 公司 ：国金黄金
 */
public class T {

    public static void main(String[] args) {

        CC a = BB.getA();
        a.setKey("5AE6C1EC04B0156EA24AC99402265936");
        a.setClientid("75537324");
        System.out.println("JSON字符串:::::::" + JSONUtil.parse(a));
        Map<String, String> map = JSONUtil.toBean(JSONUtil.parseObj(a), Map.class);
        List<String> list = new ArrayList<>();
        for (Map.Entry<String, String> vo : map.entrySet()) {
            vo.getKey();
            vo.getValue();
            if (vo.getKey() == "data") {
                list.add(vo.getKey() + JSONUtil.toJsonStr(vo.getValue()).toString());
                continue;
            }
            if (vo.getValue().length() == 0) {
                continue;
            }
            list.add(vo.getKey() + vo.getValue());
        }
        StringBuilder sb = new StringBuilder("7427B9763CCA1DD625C753FABA4AB066");
        String ss = "7427B9763CCA1DD625C753FABA4AB066clientid75537324data[{\"sendtel\":\"11\",\"weight\":\"22\",\"lebel\":\"22\",\"remark\":\"11\",\"receiptname\":\"22\",\"receiptphone\":\"11\",\"sendtelsubnum\":\"22\",\"jjprovince\":\"11\",\"sjprovince\":\"22\",\"isOrder\":\"11\",\"jjcity\":\"22\",\"sendname\":\"11\",\"paytype\":\"11\",\"sendthings\":\"22\",\"sendtelprenum\":\"22\",\"receiptnumber\":\"11\",\"sendcompany\":\"11\",\"servicemode\":\"22\",\"monthlycardno\":\"11\",\"goodtime\":\"22\",\"supportvalue\":\"22\",\"receiptelsubnum\":\"22\",\"sendphone\":\"11\",\"sjcity\":\"11\",\"jjaddress\":\"11\",\"sendnumber\":\"11\",\"isreturn\":\"22\",\"receiptelprenum\":\"22\",\"receiptel\":\"11\",\"receipcompany\":\"22\",\"cod\":\"11\",\"sjaddress\":\"22\",\"orderid\":\"11\"}]key5AE6C1EC04B0156EA24AC99402265936";
        String[] strings = list.toArray(new String[0]);
        Arrays.sort(strings);
        for (String s : strings) {
            sb.append(s);
        }
        System.out.println(sb);
        System.out.println(ss);

        System.out.println(SecureUtil.md5(sb.toString()).toUpperCase());

        String key = HttpRequest.post("http://testapi.ky-express.com/kyeopenapi/AppResourceService/ElectronicWaybillPlaceOrder")
                .header("kye", "10217")
                .header("Content-Type", "application/json")
                .header("access-token", SecureUtil.md5(sb.toString()).toUpperCase())
                .body(JSONUtil.parse(a).toString())
                .execute().body();

        System.out.println(key);
    }


}

